package com.wzcl.app.dao.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@Table(name = "KnowledgePoint",uniqueConstraints = {
        @UniqueConstraint(columnNames = {"gradeId","subjectId","chapter","point"}
        )})
@ApiModel(value = "知识点表")
public class KnowledgePoint implements Base {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ApiModelProperty(name = "年级id")
    private Integer gradeId;

    @ApiModelProperty(name = "年级")
    private String gradeName;

    @ApiModelProperty(name = "学科Id")
    private Integer subjectId;

    @ApiModelProperty(name = "学科")
    private String subjectName;

    @ApiModelProperty(name = "章节")
    private  String  chapter;

    @ApiModelProperty(name = "知识点")
    private  String  point;

    @JsonIgnore
    @OneToMany(mappedBy = "knowledgePoint")
    private List<TopicAndKnowledgePoint> topicAndKnowledgePointList;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        KnowledgePoint that = (KnowledgePoint) o;

        return new EqualsBuilder()
                .append(gradeId, that.gradeId)
                .append(subjectId, that.subjectId)
                .append(chapter, that.chapter)
                .append(point, that.point)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(gradeId)
                .append(subjectId)
                .append(chapter)
                .append(point)
                .toHashCode();
    }
}
